package cn.snowheart.decorator.javaio;

import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;

/**
 * @author liuwanxiang
 * @version 2019/06/27
 */
public class LowerCaseInputStream extends FilterInputStream {

    public LowerCaseInputStream(InputStream in) {
        super(in);
    }

    @Override
    public int read() throws IOException {
        int ch = super.read();
        return (ch == -1 ? ch : Character.toLowerCase(ch));
    }

    @Override
    public int read(byte[] b, int off, int len) throws IOException {
        int length = super.read(b, off, len);

        for (int i = off; i < off + length; i++) {
            b[i] = (byte) Character.toLowerCase((char) b[i]);
        }

        return length;
    }
}
